<template>
  <!-- 发起人管理 -->
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :model="form" label-width="150px" :inline="true">
        <el-row>
          <el-col :span="8">
            <el-form-item label="发起人名称">
              <el-input v-model="form.realname" clearable @keyup.enter.native="handleSearch" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发起人手机号">
              <el-input v-model="form.phone" clearable @keyup.enter.native="handleSearch" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入驻日期" width="236">
              <el-date-picker
                v-model="time"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" style="float:right">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <el-button style="margin-left:60px" type="primary" @click="toRoutes('AddSponsor')">添加</el-button>
              <!-- <router-link to="AddSponsor">
              <el-button style="margin-left:60px" type="primary">添加</el-button>
              </router-link>-->
              <!-- <el-button type="primary" @click="handleExport">导出</el-button> -->
              <!-- <Exprotcomponent :params="form" url="admin/ticket_export" type="php"></Exprotcomponent> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="listDiv" v-loading="tableLoading">
      <el-table ref="tableData" :data="tableData" style="width: 100%">
        <el-table-column
          fixed
          type="index"
          label="编号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column label="发起人姓名" prop="realname" align="center" width="150px" />
        <el-table-column label="发起人手机号" prop="phone" align="center"></el-table-column>
        <el-table-column label="身份证号" prop="id_number" align="center"></el-table-column>
        <el-table-column label="发起人类型" prop="level_name" align="center" width="150px" />
        <el-table-column label="签署区域" prop="partner_area" align="center" width="150px" />
        <el-table-column label="签署省份" prop="partner_province" align="center" width="150px" />
        <el-table-column label="签署板块" prop="module_name" align="center" width="150px" />
        <el-table-column label="关联城市合伙人" prop="partner_count" align="center">
          <template slot-scope="scope">
            <div
              style="color: #409eef; cursor:pointer"
              @click="useRange(scope.row.partner_identity_id)"
            >{{scope.row.partner_count || 0}}</div>
          </template>
        </el-table-column>

        <el-table-column label="签约时间" prop="partner_signtime" align="center" width="200px">
          <!-- <template slot-scope="scope">
            <span>{{(scope.row.partner_signtime - 0 ) / 1000 | date(1)}}</span>
          </template>-->
        </el-table-column>
        <!-- <el-table-column label="可提现佣金" prop="send" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.send }}</span>
          </template>
        </el-table-column>-->
        <el-table-column label="创建时间" prop="partner_signtime" align="center" width="200px" />
        <el-table-column label="操作" fixed="right" align="center" prop="status">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              @change="switchChange(scope.row.partner_identity_id)"
              :active-value="1"
              :inactive-value="-1"
            ></el-switch>
            <el-button
              size="small"
              type="text"
              @click="toRoutes('AddSponsor',scope.row.partner_identity_id,'edit')"
            >编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 关联城市合伙人 -->
    <el-dialog title="签约城市合伙人" :visible.sync="dialogFormVisible" width="60%" center>
      <div v-loading="tableLoading1">
        <el-table ref="tableData1" :data="tableData1" style="width: 100%" border>
          <el-table-column label="城市合伙人名称" prop="realname" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.realname || ''}}</span>
            </template>
          </el-table-column>
          <el-table-column label="城市合伙人手机号" prop="phone" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.phone || 0}}</span>
            </template>
          </el-table-column>
          <el-table-column label="签约板块" align="center" width="180px">
            <template slot-scope="scope">{{scope.row.module_name }}</template>
          </el-table-column>
          <el-table-column label="签约机构" prop="group_hospital_str" align="center" width="150px" />
          <el-table-column label="签约时间" prop="sign_time" align="center" width="200px">
            <!-- <template slot-scope="scope">
            <span>{{(scope.row.sign_time - 0 ) / 1000 | date(1)}}</span>
            </template>-->
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="pagesCon">
          <div>
            <el-pagination
              :current-page="form1.page"
              :page-sizes="page_sizes1"
              :page-size="form1.size"
              layout="total, sizes, prev, pager, next, jumper"
              :total="page_totals1"
              @size-change="handleSizeChange1"
              @current-change="handleCurrentChange1"
            />
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
// import commonFn from "@/utils/common";
// import filter from "@/assets/filter";
import { promoter_index, partner_detail, status } from "@/api/NewRetailSystem";
export default {
  name: "SponsorManagement",
  data() {
    return {
      form: {
        realname: "",
        phone: "",
        start_time: "",
        end_time: "",
        page: 1,
        size: 10,
      },
      form1: {
        page: 1,
        pagesize: 10,
      },
      page_sizes1: [10, 30, 50, 100],
      page_totals1: 0,
      page_sizes: [10, 30, 50, 100],
      page_totals: 0,
      tableData: [{}],
      tableLoading: false,
      dialogFormVisible: false,
      tableData1: [],
      tableLoading1: false,
      dialogNumVisible: false, //发放数量
      tableData2: [], //发放数量弹窗数据
      form2: {
        page: 1,
        pagesize: 10,
      },
      time: null,
      page_sizes2: [10, 30, 50, 100],
      page_totals2: 0,
      tableLoading2: false,
    };
  },
  watch: {
    time(val) {
      this.form.start_time = val ? val[0] : "";
      this.form.end_time = val ? val[1] : "";
    },
  },
  filters: {
    // 时间戳转化
    dates(opt) {
      if (opt) {
        // yyyy-MM-dd hh:mm:ss
        return new Date(Number(opt) * 1000).format("yyyy-MM-dd");
      } else {
        return "--";
      }
    },
  },
  activated() {
    this.getList(this.form);
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    // 路由跳转
    toRoutes(e, id, type) {
      const route = {
        name: e,
        query: { id: id, type: type },
      };
      this.$router.push(route);
      //   const routeUrl = this.$router.resolve(route);
      //   window.open(routeUrl.href, "_blank");
    },
    // 编号
    table_index(index) {
      return (this.form.page - 1) * this.form.size + index + 1;
    },
    async getList(opt) {
      console.log(9999999);
      let res = await promoter_index(opt);
      console.log(res);
      if (res.data.code == 200) {
        this.tableLoading = false;
        this.tableData = res.data.data;
        this.page_totals = res.data.meta.total;
      } else {
        this.tableLoading = false;
        this.$message({
          message: res.data.msg,
          type: "warning",
        });
      }
    },
    // 下架
    switchChange(id) {
      let data = { id };
      status(data).then((res) => {
        if (res.data.code == 200) {
          this.$message({
            message: "修改成功",
            type: "success",
          });
        } else {
          this.$message({
            message: res.data.msg,
            type: "warning",
          });
        }
      });
    },
    // 签约城市合伙人
    async useRange(id) {
      this.dialogFormVisible = true;
      let data = {
        partner_identity_id: id,
        page: this.form1.page,
        size: this.form1.size,
      };
      let res = await partner_detail(data);
      if (res.data.code == 200) {
        this.tableLoading1 = false;
        this.tableData1 = res.data.data;
        this.page_totals1 = res.data.meta.total;
      }
    },
    //   查询
    handleSearch() {
      this.form.page = 1;
      this.getList(this.form);
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.size = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // 使用范围
    handleSizeChange1(val) {
      this.form1.pagesize = val;
      this.handleUse(this.form1);
    },
    handleCurrentChange1(val) {
      this.form1.page = val;
      this.handleUse(this.form1);
    },
  },
};
</script>
<style scoped>
.app-container {
  padding: 0px !important;
  background: transparent;
}
.formDiv {
  padding: 20px;
}
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.pagesCon {
  text-align: right;
  margin-top: 20px;
}
</style>
